package net.cloudcodex.client.sheet;

import java.util.HashMap;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * 
 * @author ADaroussin
 */
public class SheetLabel extends Label implements IsSheet {

	private final Sheet sheet;

	private final HashMap<ClickHandler, HandlerRegistration> handlers = new HashMap<ClickHandler, HandlerRegistration>();

	public SheetLabel(String label, Sheet sheet) {
		super(label);

		this.sheet = sheet;
	}

	public Sheet asSheet() {
		return sheet;
	}

	public Widget asWidget() {
		return this;
	}

	public Widget getDragHandle() {
		return this;
	}

	public HandlerRegistration addClickHandler(ClickHandler handler) {
		final HandlerRegistration handlerReg = super.addClickHandler(handler);
		handlers.put(handler, handlerReg);
		return handlerReg;
	}

	public void removeClickHandler(ClickHandler handler) {
		final HandlerRegistration handlerReg = handlers.get(handler);
		if (handlerReg != null) {
			handlerReg.removeHandler();
		}
	}

}
